using System;
using System.Linq;
using SapaFinance.Domain.Model;
using SapaFinance.GenericRepository;

namespace SapaFinance.Domain
{
    public interface ICorporationSpecification : ISpecification<Corporation>
    {
        ICorporationSpecification Our();
        ICorporationSpecification NoOur();
        ICorporationSpecification IsPayer();
        ICorporationSpecification WithAccount(Guid id);
    }

    public class CorporationQueryableSpecification
       : QueryableSpecification<Corporation>
         , ICorporationSpecification
    {

        public CorporationQueryableSpecification(IUnitOfWorkConvertor unitOfWorkConvertor)
            : base(unitOfWorkConvertor)
        {
        }

        public ICorporationSpecification Our()
        {
            this.Queryable = this.Queryable.Where(c => c.Agent.IsSelfAgent);
            return this;
        }

        public ICorporationSpecification NoOur()
        {
            this.Queryable = this.Queryable.Where(c => !c.Agent.IsSelfAgent);
            return this;
        }

        public ICorporationSpecification IsPayer()
        {
            this.Queryable = this.Queryable.Where(c => c.IsPayer);
            return this;
        }

        public ICorporationSpecification WithAccount(Guid id)
        {
            this.Queryable = this.Queryable.Where(c => c.Accounts.Select(x=>x.UID).Contains(id));
            return this;
        }

    }
}